import os
import shutil

DIRECTORIES_TO_REMOVE = [ "Debug", "Release", "ipch" ]
FILES_TO_REMOVE = [ ".sdf", ".suo", ".opensdf", ".user", ".exe", ".exp", ".ilk", ".pdb" ]

def clean(dir):
	content = os.listdir(dir);
	for c in content:
		fp = os.path.join( dir, c );
		if os.path.isdir(fp):
			if c in DIRECTORIES_TO_REMOVE:
				shutil.rmtree(fp);
			else:
				clean(fp);
		if os.path.isfile(fp):
			(root, ext) = os.path.splitext(c)
			if ext in FILES_TO_REMOVE:
				try:
					os.remove(fp);
				except OSError:
					print "Cannot delete "+fp+", try closing Visual Studio."
clean(".")